package com.example.weather1.controller;

//import com.example.weather1.entity.UserEntity;
import com.example.weather1.entity.Area;
import com.example.weather1.entity.weather;
import com.example.weather1.mapper.WeatherMapper;
import com.example.weather1.vo.JsonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/weather")
public class WeatherController {

    @Resource
    WeatherMapper weatherMapper;

    @GetMapping("/all")
    public JsonResult getLists(){
        List<weather> all = weatherMapper.getAll();
        System.out.println(all);
        return JsonResult.success(all);
//        return all;
    }

    @PostMapping("/searchOneDay")
    public JsonResult OneDayWeather(@RequestBody Area oneDayArea){
        System.out.println(oneDayArea);
        weather OneDay = weatherMapper.getOneDayWeatherByArea(oneDayArea.getArea());
        System.out.println(OneDay);

        if(OneDay != null){
            return JsonResult.success(OneDay);
        }else {
            return JsonResult.failed("没有该地区数据");
        }
    }

    @PostMapping("/searchSevenDay")
    public JsonResult SevenDayWeather(@RequestBody Area oneDayArea){
        System.out.println(oneDayArea);
        List<weather> SevenDay = weatherMapper.getSevenDayWeatherByArea(oneDayArea.getArea());
        System.out.println(SevenDay);

        if(SevenDay != null){
            return JsonResult.success(SevenDay);
        }else {
            return JsonResult.failed("没有该地区 7 天数据");
        }
    }

}
